package group.igfd.manager.biz.service.impl;

import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import group.igfd.manager.biz.dao.BrandsDao;
import group.igfd.manager.biz.entity.BrandsEntity;
import group.igfd.manager.biz.service.BrandsService;
import org.springframework.util.ObjectUtils;


@Service("brandsService")
public class BrandsServiceImpl extends ServiceImpl<BrandsDao, BrandsEntity> implements BrandsService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        EntityWrapper<BrandsEntity> ew = new EntityWrapper<>();
        ew.eq("del_flag", "0");

        if(!ObjectUtils.isEmpty(params.get("key"))){
            ew.like("name", params.get("key")+"");
        }

        Page<BrandsEntity> page = this.selectPage(
                new Query<BrandsEntity>(params).getPage(),
                ew
        );

        return new PageUtils(page);
    }

    @Override
    public String getBrandName(String brandId) {
        try{
            Integer bId = Integer.valueOf(brandId);
            BrandsEntity brands = this.selectById(bId);
            if(null == brands)
                return brandId;
            return brands.getName();
        }catch(Exception e){
            return brandId;
        }
    }

}
